home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Plus Special 23
/
AMIGAplus Sonderheft 23 (2000)(Falke)(DE)[!].iso
/
Updates
/
Librarys
/
zee_ini_library
/
Sources
/
Asm
/
INI_Example.s
Wrap
Text File
|
1999-03-21
|
21KB
|
625 lines
*************************************************
*** Complex example program for INI library ***
*** © 1999 by Basty/Seasons ***
*** This program demonstrates the powerful ***
*** functions of the INI library ***
*** Assembler version ***
*** Devpac 3.18 was used for development ***
*************************************************
include "exec/types.i"
include "exec/libraries.i"
include "exec/exec_lib.i"
include "libraries/dosextens.i"
include "libraries/ini_lib.i"
include "intuition/screens.i"
include "intuition/intuition.i"
include "intuition/intuitionbase.i"
include "intuition/intuition_lib.i"
include "graphics/graphics_lib.i"
include "graphics/rastport.i"
moveq #20,d7 * Set FAIL error mark
moveq #31,d0 * Version 31.00 of ini.library
lea ININame(pc),a1 * Load A1 with ini.library
move.l 4.w,a6
jsr _LVOOpenLibrary(a6) * Open ini.library
move.l d0,_INIBase * Store ini.library base to INIBase
beq OpenINIError * Exit if error
moveq #0,d0 * Any version of intuition.library
lea IntName(pc),a1 * Load A1 with intuition.library
jsr _LVOOpenLibrary(a6) * Open intuition.library
move.l d0,_IntBase * Store intuition.library base to IntBase
moveq #0,d0 * Any version of graphics.library
lea GfxName(pc),a1 * Load A1 with graphics.library
jsr _LVOOpenLibrary(a6) * Open graphics.library
move.l d0,_GfxBase * Store graphics.library base to GfxBase
move.l _IntBase(pc),a0 * Get first screen (WB screen)
move.l ib_FirstScreen(a0),WBScreen+8
lea DefaultINI(pc),a0 * Load default INI file
lea ExampleINI(pc),a1 * Open :Example.INI file
move.l #DefaultLen,d0 * Length of it in D0
CALLINIB iniOpenDefault * Open INI file/Create default INI file
move.l d0,DefINIFile * Store loaded iniFile
beq CloseINI * Error -> close everything and end
moveq #1,d6 * Start with first screen
LoopReadScr: lea ScreenNum(pc),a0 * Store to screen number
move.l d6,d0 * Current screen number
moveq #INI_FORMAT_DEC,d1 * Use standard decimal format
moveq #0,d2 * No given length, as long as the string
* becomes.
moveq #" ",d3 * Use SPACE character as zero separator
CALLINIB iniIntToStr * Convert screen number
move.l DefINIFile(pc),a0
lea ScreenContext(pc),a1 * Find the context
moveq #0,d0 * No flags (case insensitive search)
CALLINI iniFindContext * Search for context
tst.l d0 * Found?
beq LoopReadScrDone * No -> end of search
move.l d0,CurrentContext * Store current ContextStr
lea NewScreenStr(pc),a5 * NewScreen structure to A5
move.l DefINIFile(pc),a0
lea ScreenContext(pc),a1 * Get current screen context name
lea LeftEdgeName(pc),a2 * Get left edge value
moveq #0,d0 * Default left edge is 0
moveq #0,d1 * No flags (case insensitive search)
CALLINI iniReadLong
move.w d0,(a5) * Store left edge into screen structure
move.l DefINIFile(pc),a0
lea ScreenContext(pc),a1 * Get current screen context name
lea TopEdgeName(pc),a2 * Get top edge value
moveq #0,d0 * Default top edge is 0
moveq #0,d1 * No flags (case insensitive search)
CALLINI iniReadLong
move.w d0,ns_TopEdge(a5) * Store top edge into screen structure
move.l DefINIFile(pc),a0
lea ScreenContext(pc),a1 * Get current screen context name
lea WidthName(pc),a2 * Get width value
move.l #640,d0 * Default width is 640
moveq #0,d1 * No flags (case insensitive search)
CALLINI iniReadLong
move.w d0,ns_Width(a5) * Store width into screen structure
move.l DefINIFile(pc),a0
lea ScreenContext(pc),a1 * Get current screen context name
lea HeightName(pc),a2 * Get height value
move.l #256,d0 * Default height is 256
moveq #0,d1 * No flags (case insensitive search)
CALLINI iniReadLong
move.w d0,ns_Height(a5) * Store height into screen structure
move.l DefINIFile(pc),a0
lea ScreenContext(pc),a1 * Get current screen context name
lea DepthName(pc),a2 * Get depth value
moveq #4,d0 * Default depth is 4
moveq #0,d1 * No flags (case insensitive search)
CALLINI iniReadLong
move.w d0,ns_Depth(a5) * Store depth into screen structure
move.l DefINIFile(pc),a0
lea ScreenContext(pc),a1 * Get current screen context name
lea ViewModesName(pc),a2 * Get view mode value
move.l #$8000,d0 * Default view modes are 0x8000
moveq #0,d1 * No flags (case insensitive search)
CALLINI iniReadLong
move.w d0,ns_ViewModes(a5) * Store view mode into screen structure
move.l DefINIFile(pc),a0
lea ScreenContext(pc),a1 * Get current screen context name
lea TitleName(pc),a2 * Get screen title
lea DefaultScrTitle(pc),a3 * Default screen title
moveq #0,d0 * No flags (case insensitive search)
CALLINI iniReadStr
move.l d0,ns_DefaultTitle(a5) * Store title into screen structure
moveq #256/4-1,d0 * Copy all 256 default colors to
moveq #0,d1 * updated color table
lea DefaultColTab(pc),a0
lea ScrColorTable(pc),a1
CopyDefColTabLoop: move.l (a0)+,(a1)+
move.l (a0)+,(a1)+
dbra d0,CopyDefColTabLoop
move.w ns_Depth(a5),d0 * Calculate number of colors
moveq #1,d5 * store 1 color
lsl.b d0,d5 * multiply with 2^depth
bne.s NotGreater * if lesser than 256 colors -> jump
move.w #$100,d5 * set to 256 colors
NotGreater: move.l DefINIFile(pc),a0
lea ScreenContext(pc),a1 * Get current screen context name
lea ColorTableName(pc),a2 * Get color table context item name
lea ScrColorTable(pc),a3 * Get array pointer
move.l d5,d0 * Number of entries to read
moveq #0,d1 * No flags (case insensitive search)
CALLINI iniReadWordA * Read color table array
moveq #24,d0 * We need 24 bytes of storage buffer for
* each screen we open.
CALLINI iniAllocPMem * Allocate it using ini.library
tst.l d0 * Test if error
bne.s AllocScrOk * No -> continue
move.l ns_DefaultTitle(a5),a0 * Deallocate title string (don't forget!)
CALLINIB iniFreeNameStr * Deallocate name string
bra CloseINI * Close INI file
AllocScrOk: lea Screens(pc),a0 * Add the structure to the screen list
move.l d0,a1
move.l 4.w,a6
jsr _LVOAddTail(a6) * Use exec AddTail() for this
move.l a5,a0 * Now we want to open the screen
move.l _IntBase(pc),a6 * We need intuition.library for this
jsr _LVOOpenScreen(a6) * Open the screen
move.l Screens+MLH_TAILPRED(pc),a0 * Get last screen structure added
addq.l #MLN_SIZE,a0
move.l d0,(a0)+ * Store the screen for later reuse
move.l a0,(a0) * Initialize node list of windows
move.l a0,MLH_TAILPRED(a0) * Currently there are none.
addq.l #4,(a0)
tst.l d0 * Check if screen open error
bne.s AllocScrOk2 * No -> continue
move.l ns_DefaultTitle(a5),a0 * Deallocate title string (don't forget!)
CALLINIB iniFreeNameStr * Deallocate name string
bra CloseINI
AllocScrOk2: move.l d0,a0
move.l d5,d0 * Read color map
lea sc_ViewPort(a0),a0 * Screen->ViewPort
lea ScrColorTable(pc),a1 * Load colors
move.l _GfxBase(pc),a6 * We need graphics.library
jsr _LVOLoadRGB4(a6) * Load color table
addq.l #1,d6 * Increment screen counter
bra LoopReadScr
LoopReadScrDone: moveq #1,d6 * Start with first window
LoopReadWin: lea WindowNum(pc),a0 * Store to window number
move.l d6,d0 * Current window number
moveq #INI_FORMAT_DEC,d1 * Use standard decimal format
moveq #0,d2 * No given length, as long as the string
* becomes.
moveq #" ",d3 * Use SPACE character as zero separator
CALLINIB iniIntToStr * Convert window number
addq.l #1,d6 * Next window
move.l DefINIFile(pc),a0
lea WindowContext(pc),a1 * Find the context
moveq #0,d0 * No flags (case insensitive search)
CALLINI iniFindContext * Search for context
tst.l d0 * Found?
beq LoopReadWinDone * No -> end of search
move.l d0,CurrentContext * Store current ContextStr
lea NewWindowStr(pc),a5 * NewWindow structure to A5
move.l DefINIFile(pc),a0
lea WindowContext(pc),a1 * Get current window context name
lea LeftEdgeName(pc),a2 * Get left edge value
moveq #0,d0 * Default left edge is 0
moveq #0,d1 * No